package fy.bean;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import fy.util.DBUtil;

//类名
public class CatelogBean {
	//属性（成员变量）
	private int id;
	private String category;
	private String titlename;
	private String hcategory;
	private String htitlename;
	
	PreparedStatement statement=null;
	ResultSet rs = null;
	Connection connection = null;
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getCategory() {
		return category;
	}
	public void setCategory(String category) {
		this.category = category;
	}
	public String getTitlename() {
		return titlename;
	}
	public void setTitlename(String titlename) {
		this.titlename = titlename;
	}
	public String getHcategory() {
		return hcategory;
	}
	public void setHcategory(String hcategory) {
		this.hcategory = hcategory;
	}
	public String getHtitlename() {
		return htitlename;
	}
	public void setHtitlename(String htitlename) {
		this.htitlename = htitlename;
	}
	
	
	public List<CatelogBean> findAllByHLb(String hcategory) {
		List<CatelogBean> list = new ArrayList<CatelogBean>();
		DBUtil dbUtil = new DBUtil();
		String sql = "select * from catalog where hcategory=?";
		connection = dbUtil.geConnection();
		try {
			statement = connection.prepareStatement(sql);
			statement.setString(1, hcategory);
			rs = statement.executeQuery();
			while(rs.next()) {
				CatelogBean catelogBean = new CatelogBean();
				catelogBean.setId(rs.getInt("id"));
				catelogBean.setTitlename(rs.getString("titlename"));
				catelogBean.setCategory(rs.getString("Category"));
				catelogBean.setHcategory(rs.getString("hcategory"));
				catelogBean.setHtitlename(rs.getString("htitlename"));
				list.add(catelogBean);
			}
			
		} catch (SQLException e) {
			e.printStackTrace();
		}finally {
			if (rs != null) {
				try {
					rs.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (statement != null) {
				try {
					statement.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if(connection != null) {
				try {
					connection.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			dbUtil.close();
		}
		return list;
		
	}
	
	public CatelogBean findAllByLb(String category) {
		CatelogBean catelogBean = new CatelogBean();
		DBUtil dbUtil = new DBUtil();
		String sql = "select * from catalog where category=?";
		connection = dbUtil.geConnection();
		try {
			statement = connection.prepareStatement(sql);
			statement.setString(1, category);
			rs = statement.executeQuery();
			while(rs.next()) {
				catelogBean.setId(rs.getInt("id"));
				catelogBean.setTitlename(rs.getString("titlename"));
				catelogBean.setCategory(rs.getString("Category"));
				catelogBean.setHcategory(rs.getString("hcategory"));
				catelogBean.setHtitlename(rs.getString("htitlename"));
			}
			
		} catch (SQLException e) {
			e.printStackTrace();
		}finally {
			if (rs != null) {
				try {
					rs.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (statement != null) {
				try {
					statement.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if(connection != null) {
				try {
					connection.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			dbUtil.close();
		}
		return catelogBean;
		
	}

	
	

	
	
	
}
